Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open top-level singleton collection by default in hierarchy tree #4201

Conversation

siiriylonen
Copy link
Contributor

@siiriylonen siiriylonen commented Jan 22, 2025

Open collection level by default in hierarchy tree for user convenience.

@siiriylonen siiriylonen marked this pull request as ready for review January 22, 2025 09:29
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @siiriylonen! I think this may require some adjustments, though...

This change will cause every level of the hierarchy tree to be expanded if it is a collection. For large and complex collections, this may result in an overwhelming amount of information to scroll through. Is that really what is intended?

I spoke with @EreMaijala about this, and he thought that the intent might be to only open the top node of the tree if it is a collection and other items are not open/selected. That narrower scope for the special case seems more likely to be universally beneficial (though if "all collections always expanded" is really what you want, maybe we should consider a config setting for that so it doesn't change the default behavior for users that won't want it).

@siiriylonen
Copy link
Contributor Author

I see, yes the intention here was to only open the one and not many. I'll rethink.

@demiankatz
Copy link
Member

Thanks, @siiriylonen! Let me know if I can be of any assistance as you revise. Also note that if you start up the default test environment (with phing startup) it includes some sample collection data that might be useful for testing. To confirm my concerns about the initial version of this code, I just spun up a test instance, turned on collections and hierarchies in config.ini, and then filtered down to the collection.mrc example records. This allowed me to look at a deep nested hierarchy and confirm that all levels opened up with this code.

Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @siiriylonen -- this is looking much better. I just have one more question, which might or might not actually be relevant. :-)

if ($hasChildren) {
$liClasses[] = 'hierarchy-tree__parent';
}
if ('collection' === $node->type) {
$liClasses[] = 'hierarchy-tree__collection';
$icon = 'hierarchy-collection';
if ($nodeId === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check that $parentNodeId is empty here if we only want to impact the very top of the tree? It seems to be working fine for me as-is in my test environment, but that data is very simple... I'm not too familiar with the code (so @EreMaijala may have a better-informed opinion), but since there is recursion here, I thought there might be reason to add an extra restriction.

Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @siiriylonen. This is looking good to me now, but I have one small optimization suggestion below.

if ($hasChildren) {
$liClasses[] = 'hierarchy-tree__parent';
}
if ('collection' === $node->type) {
$liClasses[] = 'hierarchy-tree__collection';
$icon = 'hierarchy-collection';
if ($nodeId === 0 && !$parentNodeId && count($nodes) === 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be a good idea to set $nodeCount = count($nodes); above the foreach loop and then use the variable here, so if there are a large number of nodes to check, we only need to perform the count operation a single time?

@demiankatz demiankatz changed the title Open collection level by default in hierarchy tree Open top-level singleton collection by default in hierarchy tree Feb 6, 2025
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @siiriylonen, this looks great to me now!

@demiankatz demiankatz merged commit d80a1bd into vufind-org:dev Feb 6, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants